import pymysql

# 2、创建数据库链接
connect = pymysql.connect(host="master", port=3306, user="root", password="123456", database="bigdata")

# 3、获取游标，用于执行sql
cursor = connect.cursor()

# 4、创建表
cursor.execute("""
create table if not exists users (
    id bigint,
    `name` varchar(20),
    password varchar(20)
)
""")

# 5、插入数据
print(cursor.execute("insert into users(id,name,password) values (100,'张三','123456')"))

# 修改数据
print(cursor.execute("update users set password='111111' where name='张三'"))

# 删除数据
print(cursor.execute("delete from users where name='张三'"))

# 提交事务
connect.commit()
connect.close()
